﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace zielonka.co.uk.extensions.system.data
{
    // Description: This extension method will remove duplicate rows from the DataTable that it is called from.
    /*
        dt.RemoveDuplicateRows()
    */

    public static partial class DataTableExtensions
    {
        /// <summary>
        /// Removes duplicates from the data table.
        /// </summary>
        /// <param name="dt"></param>
        /// <remarks>
        /// This extension method will remove duplicate rows from the DataTable that it is called from.
        /// </remarks>

        public static void RemoveDuplicateRows(ref DataTable dt)
        {
	        string[] columnList = new string[dt.Columns.Count];
	        for (int counter = 0; counter <= dt.Columns.Count - 1; counter++) {
		        columnList[counter] = dt.Columns[counter].ColumnName;
	        }
	        dt = dt.DefaultView.ToTable(true, columnList);
        }
    }
}
